package com.xhwl.centiotdata.service.integrateconfig;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xhwl.centiotdata.pojo.dto.eesd.EesdConfigDTO;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author： lianghz
 * @Description：
 * @Date 2021/12/16/ 15:20
 */
@Component
public class EESDIntegrationConfig extends IntegrationConfig<Integer, List<EesdConfigDTO>> {

    @Override
    public List<EesdConfigDTO> getIntegrationConfig(Integer productId) {
        List<EesdConfigDTO> collect = IntegrationConfig.integrationConfigList.stream()
                .filter(deviceProjSupplierCategory -> deviceProjSupplierCategory.getProperties() != null && productId.equals(deviceProjSupplierCategory.getProductId()))
                .map(deviceProjSupplierCategory -> {
                    JSONObject properties = deviceProjSupplierCategory.getProperties();
                    EesdConfigDTO eesdConfigDTO = JSON.toJavaObject(properties, EesdConfigDTO.class);
                    eesdConfigDTO.setProjectId(deviceProjSupplierCategory.getProjectId());
                    return eesdConfigDTO;
                }).collect(Collectors.toList());
        return collect;
    }

}
